﻿using System;
using RecipeSL.RecipeServiceReference;
using System.ComponentModel;

namespace RecipeSL
{
    public interface IServiceAgent
    {
        void GetRecipes(EventHandler<GetRecipesCompletedEventArgs> callback);
        void UpdateRecipe(Recipe recipe, EventHandler<AsyncCompletedEventArgs> callback);
    }

    public class ServiceAgent : IServiceAgent
    {
        public void GetRecipes(EventHandler<GetRecipesCompletedEventArgs> callback)
        {
            RecipeServiceClient proxy = new RecipeServiceClient();
            proxy.GetRecipesCompleted += callback;
            proxy.GetRecipesAsync();
        }

        public void UpdateRecipe(Recipe recipe, EventHandler<AsyncCompletedEventArgs> callback)
        {
            RecipeServiceClient proxy = new RecipeServiceClient();
            proxy.UpdateRecipeCompleted += callback;
            proxy.UpdateRecipeAsync(recipe);
        }
    }
}